<template>
  <basic-container>
    <avue-crud :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad">

      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page ref="searchSerSelect" label="serviceName" value="serviceNo" :select.sync="search.serviceNo" :url="website.searchLink.serviceUrl" placeholder-text="服务商" filter-key="searchParam"></select-page>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          icon="el-icon-view"
          size="small"
          type="text"
          @click.stop="handleView(scope.row)"
          >查 看</el-button
        >
      </template>
      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page ref="searchSerSelect" label="serviceName" value="serviceNo" :select.sync="search.serviceNo" :url="website.searchLink.serviceUrl" placeholder-text="代理商编号" filter-key="searchParam"></select-page>
      </template>
    </avue-crud>

    <serviceQxChagne ref="serviceQxChagne" :qxType="1" @resetFun="refreshChange"/>

  </basic-container>
</template>

<script>
import {mapGetters} from "vuex";
import selectPage from "@/components/select-page/select-page";
import serviceQxChagne from "@/components/rb-service/service-qxChagne";
import { changeRecordList } from "@/api/rb-oem/serviceinfo/service_info_details";

export default {
  components: {
    selectPage,serviceQxChagne
  },
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height:'auto',
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        addBtn:false,
        editBtn:false,
        delBtn:false,
        selection: false,
        searchMenuSpan: 6,
        columnBtn: false,
        labelWidth:120,
        searchLabelWidth:120,
        column: [
          {
            label: "服务商编号",
            searchLabel: "服务商",
            prop: "serviceNo",
            type: 'select',
            addDisplay: false,
            editDisplay: false,
            search: true,
            span: 24,
            overHidden: true,
            rules: [
              {
                required: true,
                message: "请选择服务商",
                trigger: "blur",
              },
            ],
          },
          {
            label: "服务商名称",
            labelWidth: 100,
            prop: "serviceName",
            span: 12,
            rules: [
              {
                required: true,
                message: "请输入服务商名称",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: '',
            prop: 'isSelectChild',
            type: 'select',
            multiple: false,
            dataType: "string",
            showColumn: false,
            hide: true,
            search: true,
            searchType:"checkbox",
            // searchSpan:2,
            searchLabelWidth: '0',
            dicData: [{
              label:'包含下级',
              value: 1
            }]
          },
          {
            label: "变更类型",
            prop: "changeType",
            type: "switch",
            search: true,
            dicUrl: "/api/blade-system/dict/dictionary?code=service_qx_type",
            dataType: "number",
            showColumn: false,
            slot: true,
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            overHidden: true,
          },
          {
            label: "变更时间",//
            search: false,
            prop: "createTime",
            type: "datetime",
            rules: [
              {
                required: true,
                message: "请输入提现日期",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
              search: true,
              label: "变更时间",
              type: 'daterange',
              prop:'createTimeArr',
              searchRange: true,
              format:'yyyy-MM-dd',
              valueFormat:'yyyy-MM-dd',
              startPlaceholder: '开始时间',
              endPlaceholder: '结束时间',
              hide:true,
              display:false,
              overHidden: true,
          },
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
    handleView(row){
      this.$refs.serviceQxChagne.initView(JSON.parse(row.changeJson))
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then(res => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage){
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize){
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      let queryParam = Object.assign(params, this.query)
      if(queryParam.createTimeArr){
        queryParam.beginTime = queryParam.createTimeArr[0];
        queryParam.endTime = queryParam.createTimeArr[1];
        delete queryParam.createTimeArr;
      }

      changeRecordList(page.currentPage, page.pageSize, queryParam).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    }
  }
};
</script>

<style>
</style>
